package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.tools.CastTime;

import java.util.HashMap;
import java.util.List;

/**
 * 待取货适配器
 * Created by KuKa on 2017/6/9.
 */

public class OrderAdapter extends BaseAdapter {
    private Context context;
    private List<HashMap<String,String>>list;
    private Callback mCallback;



    public interface  Callback{
        void onclick(int v);
        void onclick1(int v);
    }
    public void setOnClick(Callback callback){
        this.mCallback=callback;
    }

    public OrderAdapter(Context context, List<HashMap<String,String>> list) {
        this.context=context;
        this.list=list;

    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
       ViewHolder holder;
        View view;
        if (convertView==null){
            view = View.inflate(context, R.layout.billlist_item,null);
            holder = new ViewHolder();
            holder.billAddPrice = (Button) view.findViewById(R.id.bill_addprice);
            holder.billContent = (Button) view.findViewById(R.id.bill_content);
            holder.billexplain = (TextView) view.findViewById(R.id.bill_explain);
            holder.billno = (TextView) view.findViewById(R.id.bill_no);
            holder.billprice = (TextView) view.findViewById(R.id.bill_price);
            holder.billtype = (TextView) view.findViewById(R.id.billtype);
            holder.billtime = (TextView) view.findViewById(R.id.bill_sendtime);
            view.setTag(holder);
        }else {
            view=convertView;
            holder= (ViewHolder) view.getTag();
        }

        /**
         *  map.put("consignorAddr",consignorAddr);
         map.put("id",id);
         map.put("intro",intro);
         map.put("introImage",introImage);
         map.put("orderCode",orderCode);
         map.put("totalAmount",totalAmount);
         map.put("publishTime",publishTime);
         map.put("type",type);

         CastTime.CastTime(Long.valueOf(list.get(position).get("publishTime"))
         */
        String id = list.get(position).get("id");
        holder.billtime.setText(list.get(position).get("publishTime"));
        holder.billtype.setText(list.get(position).get("type"));
        holder.billprice.setText(list.get(position).get("totalAmount"));
        holder.billexplain.setText(list.get(position).get("intro"));
        holder.billno.setText(list.get(position).get("orderCode"));

        holder.billAddPrice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallback!=null){
                    mCallback.onclick(position);
                }
            }
        });
        holder.billContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallback!=null){
                    mCallback.onclick1(position);
                }
            }
        });
        notifyDataSetChanged();

        return view;
    }

    class ViewHolder{
        private TextView billprice,billno,billtype,billexplain,billtime;
        private Button billContent,billAddPrice;
    }

}
